package com.zhuoxin.dao.admin;

import org.apache.commons.lang.StringUtils;
import org.hibernate.Criteria;
import org.hibernate.Query;
import org.hibernate.criterion.Restrictions;

import com.zhuoxin.bean.model.Link;
import com.zhuoxin.bean.model.LinkSO;
import com.zhuoxin.dao.BaseDAOImpl;

public class LinkDAOImpl extends BaseDAOImpl<Link, LinkSO> implements LinkDAO {

	@Override
	public String getHqlWhere(LinkSO so) {
		return null;
	}

	@Override
	public void setCriteriaParams(Criteria criteria, LinkSO so) {
		
		if(StringUtils.isNotEmpty(so.getName())){
			criteria.add(Restrictions.ilike("name", "%"+StringUtils.trim(so.getName())+"%"));
		}
		
		if(so.getSort()!=null){
			criteria.add(Restrictions.eq("sort",so.getSort()));
		}
		
		if(so.getPosition()!=null){
			criteria.add(Restrictions.eq("position", so.getPosition()));
		}
		
	}

	@Override
	public void setQueryParams(Query query, LinkSO so) {
		
	}

	@Override
	public void switchVO2PO(Link po, LinkSO so) {
		if(StringUtils.isNotEmpty(so.getName())){
			po.setName(StringUtils.trim(so.getName()));
		}
		
		if(StringUtils.isNotEmpty(so.getHref())){
			po.setHref(StringUtils.trim(so.getHref()));
		}
		
		if(so.getSort()!=null){
			po.setSort(so.getSort());
		}
		
		if(StringUtils.isNotEmpty(so.getPath())){
			po.setPath(StringUtils.trim(so.getPath()));
		}
		
		
		if(so.getPlace()!=null){
			po.setPlace(so.getPlace());
		}
		
		if(so.getIsHot()!=null){
			po.setIsHot(so.getIsHot());
		}
		
		if(so.getPosition()!=null){
			po.setPosition(so.getPosition());
		}
		
	}



}
